import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../../providers/order_provider.dart';

class OrderPrice extends StatefulWidget {
  const OrderPrice({Key? key}) : super(key: key);

  @override
  _OrderPriceState createState() => _OrderPriceState();
}

class _OrderPriceState extends State<OrderPrice> {
  Map orderPrice = {};
  @override
  Widget build(BuildContext context) {
    orderPrice = Provider.of<OrderProvider>(context).computedPrice;
    // print(orderPrice);

    return Container(
      margin: const EdgeInsets.fromLTRB(10, 10, 10, 100),
      padding: const EdgeInsets.all(10),
      decoration: BoxDecoration(
        border: Border.all(width: 1, color: Colors.grey.shade300)
      ),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              const Text('商品总价：'),
              Text('￥ '+orderPrice['total_price'].toString())
            ],
          ),
          orderPrice['coupon_price'] == '0'
          ? 
          Container()
          :
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              const Text('优惠券抵扣：'),
              Text('￥ '+orderPrice['coupon_price'].toString())
            ],
          ),

          orderPrice['deduction_price'] == 0
          ? 
          Container()
          :
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              const Text('积分抵扣：'),
              Text('￥ '+orderPrice['deduction_price'].toString())
            ],
          ),
        ],
      ),
    );
  }
}